package com.biz.primus.ms.tms.dao.po;

import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.model.tms.enums.DeliveryOrderStatus;
import com.biz.primus.model.tms.enums.SignType;
import com.biz.primus.ms.base.jpa.po.BaseEntity;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

/**
 * DeliveryOrderPo
 * 配送单
 *
 * @author JKLiues
 * @date 2017/11/21
 */
@Getter
@Setter
@Entity
@Table(name = "tb_tms_delivery_order")
public class DeliveryOrderPo extends BaseEntity {
    private static final long serialVersionUID = -520495557994560309L;


    /**
     * 订单来源
     */
    @Column(length = 20)
    private String orderSource;

    /**
     * 订单编号
     */
    @Column(length = 50, nullable = false)
    private String orderCode;

    /**
     * 配送单号
     */
    @Column(length = 50, nullable = false, unique = true)
    private String deliveryCode;

    /**
     * 门店编号
     */
    @Column(length = 20)
    private String depotCode;

    /**
     * 门店名称
     */
    @Column(length = 20)
    private String depotName;

    /**
     * 配送员编号
     */
    @Column(length = 50)
    private String deliveryUserNo;

    /**
     * 配送员用户名
     */
    @Column
    private String deliveryUserName;

    /**
     * 配送员联系方式
     */
    @Column(length = 11)
    private String deliveryUserMobile;

    /**
     * 配送状态
     */
    @Column
    @Enumerated(EnumType.STRING)
    private DeliveryOrderStatus deliveryStatus = DeliveryOrderStatus.WAIT_BE_SINGLE;

    /**
     * 配送单部分签收明细
     */
    @OneToMany(mappedBy = "deliveryOrder", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<DeliverySignItemPo> deliveryPartSignItems;

    /**
     * 延期配送时间
     */
    @Column
    private Timestamp delayDeliveryTime;

    /**
     * 收单经度
     */
    @Column(columnDefinition = "decimal(9,6)")
    private BigDecimal orderTakeLon;

    /**
     * 收单纬度
     */
    @Column(columnDefinition = "decimal(9,6)")
    private BigDecimal orderTakeLat;

    /**
     * 收单时间
     */
    @Column
    private Timestamp orderTakeTime;

    /**
     * 出发经度
     */
    @Column(columnDefinition = "decimal(9,6)")
    private BigDecimal startLon;

    /**
     * 出发纬度
     */
    @Column(columnDefinition = "decimal(9,6)")
    private BigDecimal startLat;

    /**
     * 出发时间
     */
    @Column(columnDefinition = "decimal(9,6)")
    private Timestamp startTime;

    /**
     * 到达经度
     */
    @Column(columnDefinition = "decimal(9,6)")
    private BigDecimal arriveLon;

    /**
     * 到达纬度
     */
    @Column(columnDefinition = "decimal(9,6)")
    private BigDecimal arriveLat;

    /**
     * 到达时间
     */
    @Column
    private Timestamp arriveTime;

    /**
     * 完成经度
     */
    @Column(columnDefinition = "decimal(9,6)")
    private BigDecimal completeLon;

    /**
     * 完成纬度
     */
    @Column(columnDefinition = "decimal(9,6)")
    private BigDecimal completeLat;

    /**
     * 完成时间
     */
    @Column
    private Timestamp completeTime;

    /**
     * 完成备注
     */
    @Column
    private String remark;

    /**
     * 签收类型
     */
    @Column
    @Enumerated(EnumType.STRING)
    private SignType signType;

    /**
     * 有效状态
     * 已取消的订单保持在tms系统中的记录
     */
    @Enumerated(EnumType.STRING)
    private CommonStatus status = CommonStatus.ENABLE;

    /**
     * 回滚配送单状态
     */
    public void init() {
        this.deliveryUserNo = null;
        this.deliveryUserName = null;
        this.deliveryUserMobile = null;
        this.deliveryStatus = DeliveryOrderStatus.WAIT_BE_SINGLE;
        this.orderTakeLon = null;
        this.orderTakeLat = null;
        this.orderTakeTime = null;
        this.startLon = null;
        this.startLat = null;
    }
}
